package pt.iscte.poo.example.simplewindow;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;

import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;


public class SimpleWindow implements MouseListener {

	private JFrame window = new JFrame();
	private SimpleContentPane pane = new SimpleContentPane();
	private JLabel gameMessages = new JLabel("Game messages are displayed here");
	
	private class SimpleContentPane extends JComponent {
		private BufferedImage image;

		public void add(BufferedImage image) {
			this.image = image;			
		}
		
		public void paint(Graphics g){
			g.drawImage(image, 0, 0, null);
			System.out.println("paint");
		}
		
	}
	
	public SimpleWindow() {

		pane.setPreferredSize(new Dimension(100, 100));
		window.getContentPane().setLayout(new BorderLayout());
		window.getContentPane().add(pane, BorderLayout.CENTER);
		window.getContentPane().add(gameMessages, BorderLayout.SOUTH);

		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
		window.pack();
		window.setResizable(false);
		window.setVisible(true);
//		addKeyListener(this);
		window.addMouseListener(this);

	}
	public void add(BufferedImage image) {
		pane.add(image);
	}
	public void refresh() {
		System.out.println("refresh");
//		pane.repaint();
		window.repaint();
//		window.getContentPane().repaint();
	}
	@Override
	public void mouseClicked(MouseEvent arg0) {
		System.out.println("Clic " + arg0.getPoint());
		
	}
	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	
}
